package org.september.pisces.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.september.pisces.module.api.PiscesModule;
import org.september.pisces.module.api.WebMenu;
import org.september.pisces.task.controller.TaskController;
import org.september.pisces.task.service.DynamicScheduledTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;


/**
 * 标注service，用于主工程发现插件模块
 * @author yexinzhou
 *
 */
@Configuration
@ComponentScan("org.september.pisces.task")
public class TaskModule implements PiscesModule{

	public static final String 定时任务 ="定时任务";
	
	private static Map<String,List<WebMenu>> moduleMap = new HashMap<>();
	
	static {
		List<WebMenu> menus1 = new ArrayList<>();
		menus1.add(new WebMenu("定时任务-定时任务", TaskController.List_Page, "layui-icon-component")//icon class是个问题
				.addPermission("列表页面", PiscesTaskPermission.定时任务列表.getUrls())
				.addPermission("暂停恢复任务", PiscesTaskPermission.暂停恢复任务.getUrls()));
		moduleMap.put(定时任务, menus1);
	}
	
	@Autowired
	private DynamicScheduledTaskService dynamicScheduledTaskService;
	
	public static List<WebMenu> getWebMenus(String moduleName) {
		return moduleMap.get(moduleName);
    }
	
	public TaskModule(){
		System.out.println(this.getClass().getName()+" init..");
	}

	public String[] getMyBatisMapperLocation() {
		return new String[] {"classpath:"+this.getClass().getPackageName().replace(".", "/")+"/mapper/*.xml"};
	}
	
	public String[] getEntityPackages() {
		return new String[] {this.getClass().getPackageName()+".entity"};
    }

	@Override
	public void init() {
		dynamicScheduledTaskService.resetTaskPo();
		dynamicScheduledTaskService.startHeartBeat();
	}
}
